package com.sxhuayuan.parking.controller.salesman;

import com.sxhuayuan.parking.compenent.Page;
import com.sxhuayuan.parking.compenent.Pageable;
import com.sxhuayuan.parking.compenent.web.RespMessage;
import com.sxhuayuan.parking.controller.BaseController;
import com.sxhuayuan.parking.entity.ParkingLot;
import com.sxhuayuan.parking.entity.Salesman;
import com.sxhuayuan.parking.plugin.parking.ParkingPlugin;
import com.sxhuayuan.parking.service.ParkingLotService;
import com.sxhuayuan.parking.service.PluginService;
import com.sxhuayuan.parking.service.SalesmanService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;
import java.util.stream.Collectors;

@RestController("salesmanParkingLotController")
@RequestMapping("/salesman/parkinglot")
public class ParkingLotController extends BaseController {

	@Resource(name = "parkingLotServiceImpl")
	ParkingLotService parkingLotService;

	@Resource(name = "salesmanServiceImpl")
	SalesmanService salesmanService;

	@Resource(name = "pluginServiceImpl")
	PluginService pluginService;

	/**
	 * 停车场分页条件查询
	 */
	@RequestMapping("/list")
	public RespMessage list(@RequestBody Pageable pageable) {

		Salesman salesman = salesmanService.getCurrent();
		if (salesman == null) {
			return invalidToken();
		}
		Page<ParkingLot> page = parkingLotService.findPage(pageable, salesman);
		return successResp(page);

	}

	@RequestMapping(value = "/pluginlist", method = RequestMethod.GET)
	public RespMessage pluginList() {
		Map<String, String> map = pluginService.getParkingPlugins().stream().collect(Collectors.toMap(ParkingPlugin::getId, ParkingPlugin::getName));
		return RespMessage.builder().success().setDatas(map).build();
	}

}
